package com.smartpro.mis.modular.business.controller;

import com.smartpro.mis.core.base.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.smartpro.mis.modular.system.model.Price;
import com.smartpro.mis.modular.business.service.IPriceService;

/**
 * 价格策略控制器
 * @Author Mengiy
 * @Date 2019-04-10 16:54:26
 */
@RestController
@RequestMapping("/api/service/price")
public class PriceController extends BaseController {

    private String PREFIX = "/business/price/";

    @Autowired
    private IPriceService priceService;

    /**
     * 跳转到价格策略首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "price.html";
    }

    /**
     * 跳转到添加价格策略
     */
    @RequestMapping("/price_add")
    public String priceAdd() {
        return PREFIX + "price_add.html";
    }

    /**
     * 跳转到修改价格策略
     */
    @RequestMapping("/price_update/{priceId}")
    public String priceUpdate(@PathVariable Integer priceId, Model model) {
        Price price = priceService.selectById(priceId);
        model.addAttribute("item",price);
        return PREFIX + "price_edit.html";
    }

    /**
     * 获取价格策略列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    @RequiresAuthentication
    public Object list(String condition) {
        return priceService.selectList(null);
    }

    /**
     * 新增价格策略
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @RequiresAuthentication
    public Object add(Price price) {
        priceService.insert(price);
        return SUCCESS_TIP;
    }

    /**
     * 删除价格策略
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @RequiresAuthentication
    public Object delete(@RequestParam Integer priceId) {
        priceService.deleteById(priceId);
        return SUCCESS_TIP;
    }

    /**
     * 修改价格策略
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Price price) {
        priceService.updateById(price);
        return SUCCESS_TIP;
    }

    /**
     * 价格策略详情
     */
    @RequestMapping(value = "/detail/{priceId}")
    @ResponseBody
    @RequiresAuthentication
    public Object detail(@PathVariable("priceId") Integer priceId) {
        return priceService.selectById(priceId);
    }
}
